﻿Public Class FormPlanXJ
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim objXjPgd As New clsXjPgd
    Private Sub FormPlanXJ_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dgv.Font = New Font("UTF-8", 14)
        setDgvData()
    End Sub
    Private Sub setDgvData()
        Dim dt As DataTable = objXjPgd.getXjPgd(Now.ToShortDateString(), Now.ToShortDateString())
        If dt.Rows.Count > 0 Then
            dt.Columns.Add("validity_name")
            For Each row As DataRow In dt.Rows
                If row("validity") = "0" Then
                    row("validity_name") = "无效"
                Else
                    row("validity_name") = "有效"
                End If
            Next
        End If
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dt
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            cmb_Type_JL.Items.Clear()
            cmb_Type_JL.Items.Add(dgv.SelectedRows(0).Cells("Coljp_type").Value.ToString())
            cmb_Type_JL.SelectedIndex = 0
            txt_count_JL.Value = Decimal.Parse(dgv.SelectedRows(0).Cells("Col_jp_layer_num").Value.ToString())
            txt_size_JL.Text = dgv.SelectedRows(0).Cells("Coljp_size").Value.ToString()
            txt_size_bore_JL.Text = dgv.SelectedRows(0).Cells("Col_jp_size_bore").Value.ToString()
            txt_jp_st_wt.Text = dgv.SelectedRows(0).Cells("Col_jp_st_wt").Value.ToString()
            txt_finish_count_JL.Value = Decimal.Parse(dgv.SelectedRows(0).Cells("Colfinish_count").Value.ToString())
        End If
    End Sub
    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_finish_count_JL.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub
    Private Sub btn_Save_Click(sender As Object, e As EventArgs) Handles btn_Save.Click
        'If txt_finish_count_JL.Value > txt_count_JL.Value Then
        '    MsgBox("完成数量大于计划数量！", vbYes, "提示")
        '    Exit Sub
        'End If
        If txt_finish_count_JL.Value <= 0 Then
            MsgBox("完成数量需大于0", vbYes, "提示")
            Exit Sub
        End If
        If MsgBox("确认要进行保存吗？", vbYesNo, "提示") = vbYes Then
            Dim rtn As Integer = objXjPgd.updateFinishCount(txt_finish_count_JL.Value.ToString(),
                                                            dgv.SelectedRows(0).Cells("sys_id").Value.ToString(),
                                                            dgv.SelectedRows(0).Cells("b_pgd_mes_sys_id").Value.ToString())
            If rtn <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                setDgvData()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
    End Sub
End Class